<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/08/18 0018
 * Time: 13:56:06
 */
namespace app\admin\Controller;
use app\common\controller\Curt;
use think\Db;

class Message extends Curt{
    //用户消息列表
    public function getall()
    {
        $where['type']=1;
        $keyword=input('get.keyword');
        if($keyword){
            $where['b.user_realname']=['like','%'.$keyword.'%'];//模糊查询or可以一个条件中写多个字段以‘|’分开
            $this->assign('keyword',$keyword);
        }
        $state=trim(input('get.state'));
        if($state){
            $where['a.state']=$state;
            $this->assign('state',$state);
        }
        $list=Db::name('message')->alias('a')
            ->join('ec_user b','a.user_id=b.id',left)
            ->where($where)
            ->field('a.*,b.user_realname')
            ->order('a.id desc')
            ->paginate();
        $page = $list->render();
        $listinfo=$list->toArray();
        $this->assign(
            ['message'=>$listinfo['data']],
            ['page'=>$page]
        );
    }
    //商户消息列表
    public function shoplist(){

        $where['type']=2;
        $keyword=input('get.keyword');
        if($keyword){
            $where['b.shop_name']=['like','%'.$keyword.'%'];//模糊查询or可以一个条件中写多个字段以‘|’分开
            $this->assign('keyword',$keyword);
        }
        $state=trim(input('get.state'));
        if($state){
            $where['a.state']=$state;
            $this->assign('state',$state);
        }
        $list=Db::name('message')->alias('a')
            ->join('ec_shop b','a.shop_id=b.id',left)
            ->where($where)
            ->field('a.*,b.shop_name')
            ->order('a.id desc')
            ->paginate();
        $page = $list->render();
        $listinfo=$list->toArray();
        $this->assign(
            ['message'=>$listinfo['data']],
            ['page'=>$page]
        );
        return $this->fetch();
    }

    public function delshopmsg($id)
    {
        $arr = explode(',', $id);
        $i = 0;

        foreach ($arr as $k => $v) {
            if (!$v) {
                continue;
            }
            $this->model->destroy($v,true);
            $i++;
        }
        $this->success('删除' . $i . '条数据', url('shoplist'));
    }

}